package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.ContractManage;
import com.ruoyi.system.service.IContractManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ContractPlanAmountMapper;
import com.ruoyi.system.domain.ContractPlanAmount;
import com.ruoyi.system.service.IContractPlanAmountService;

/**
 * 账款计划Service业务层处理
 *
 * @author ruoyi
 * @date 2024-03-14
 */
@Service
public class ContractPlanAmountServiceImpl implements IContractPlanAmountService
{
    @Autowired
    private ContractPlanAmountMapper contractPlanAmountMapper;

    @Autowired
    private IContractManageService contractManageService;

    /**
     * 查询账款计划
     *
     * @param id 账款计划主键
     * @return 账款计划
     */
    @Override
    public ContractPlanAmount selectContractPlanAmountById(Long id)
    {
        return contractPlanAmountMapper.selectContractPlanAmountById(id);
    }
    @Override
    public List<ContractPlanAmount> selectContractPlanAmountByContractId(Long contractId)
    {
        return contractPlanAmountMapper.selectContractPlanAmountByContractId(contractId);
    }

    /**
     * 查询账款计划列表
     *
     * @param contractPlanAmount 账款计划
     * @return 账款计划
     */
    @Override
    public List<ContractPlanAmount> selectContractPlanAmountList(ContractPlanAmount contractPlanAmount)
    {
        return contractPlanAmountMapper.selectContractPlanAmountList(contractPlanAmount);
    }

    /**
     * 新增账款计划
     *
     * @param contractPlanAmount 账款计划
     * @return 结果
     */
    @Override
    public int insertContractPlanAmount(ContractPlanAmount contractPlanAmount)
    {
        //查询合同信息
        ContractManage contractManage = contractManageService.selectContractManageById(contractPlanAmount.getContractId());
        if(contractManage != null){
            String contractType = contractManage.getContractType();
            contractPlanAmount.setContractType(contractType);
        }
        contractPlanAmount.setCreateTime(DateUtils.getNowDate());
        return contractPlanAmountMapper.insertContractPlanAmount(contractPlanAmount);
    }

    /**
     * 修改账款计划
     *
     * @param contractPlanAmount 账款计划
     * @return 结果
     */
    @Override
    public int updateContractPlanAmount(ContractPlanAmount contractPlanAmount)
    {
        //查询合同信息
        ContractManage contractManage = contractManageService.selectContractManageById(contractPlanAmount.getContractId());
        if(contractManage != null){
            String contractType = contractManage.getContractType();
            contractPlanAmount.setContractType(contractType);
        }
        contractPlanAmount.setUpdateTime(DateUtils.getNowDate());
        return contractPlanAmountMapper.updateContractPlanAmount(contractPlanAmount);
    }

    /**
     * 批量删除账款计划
     *
     * @param ids 需要删除的账款计划主键
     * @return 结果
     */
    @Override
    public int deleteContractPlanAmountByIds(Long[] ids)
    {
        return contractPlanAmountMapper.deleteContractPlanAmountByIds(ids);
    }

    /**
     * 删除账款计划信息
     *
     * @param id 账款计划主键
     * @return 结果
     */
    @Override
    public int deleteContractPlanAmountById(Long id)
    {
        return contractPlanAmountMapper.deleteContractPlanAmountById(id);
    }
}
